<template>
  <div>
    <van-goods-action>
     <van-goods-action-icon icon="chat-o" text="客服" />
     <van-goods-action-icon icon="cart-o" text="购物车" @click="$router.push({name:'ShoppingCart'})" />
     <van-goods-action-icon icon="star" text="收藏" color="gray" />
     <van-goods-action-button type="warning" text="加入购物车" @click="addCart"  />
     <van-goods-action-button type="danger" text="立即购买" @click="buy" />
   </van-goods-action>
  </div>
</template>

<script>
export default {
  data() {
    return {
      name:"",
      content:'',
      sale:0,
      img:'',
      transport:"",
      price:0,
      type_id:0,
    }
  },
  methods: {
    buy(){
      this.$router.push({ name: "Buy", query: { id: this.$route.query.id } });
    },
    addCart(){
      this.$http
        .get("/work/box-horse/addcart.php", { 
          params:
           { name: this.name,
             content:this.content,
             sale:this.sale,
             img:this.img,
             transport:this.transport,
             price:this.price,
             type_id:this.type_id
         } })
        .then((res) => {
          console.log(res);

        })
        .catch((err) => {});
    }
  },
   mounted() {
      this.$http
        .get("/work/box-horse/cartsearch.php", { 
          params:
           { id: this.$route.query.id } })
        .then((res) => {
          this.name = res.data.data[0].name;
          this.content = res.data.data[0].content;
          this.sale = res.data.data[0].sale;
          this.img = res.data.data[0].img;
          this.transport = res.data.data[0].transport;
          this.price = res.data.data[0].price;
          this.type_id = res.data.data[0].type_id;

        })
        .catch((err) => {});

  },
};
</script>
<style lang="scss" scoped>

</style>